package com.tqyan.model.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @description 论文标题
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/11 17:51
 */
@Getter
@AllArgsConstructor
public enum PaperTitleEnum {

    SUMMARY(0, "", "摘要"),
    KEYWORD(1, "", "关键词"),
    TEXT_1(2, "一", "问题的提出"),
    TEXT_2(3, "二", "文献综述"),
    TEXT_3(4, "三", "相关概念的界定"),
    TEXT_4(5, "四", "研究方法"),
    TEXT_5(6, "五", "结果与讨论、分析"),
    TEXT_6(7, "六", "建议与研究不足之处"),
    REFERENCE(8, "", "参考文献"),
    ;

    private final int value;
    private final String node;
    private final String title;

    public static PaperTitleEnum get(Integer value) {
        if (null == value) {
            return null;
        }
        return Arrays.stream(PaperTitleEnum.values())
                .filter(e -> e.value == value).findFirst().orElse(null);
    }

    public static PaperTitleEnum getByNode(String node) {
        if (StringUtils.isBlank(node)) {
            return null;
        }
        return Arrays.stream(PaperTitleEnum.values())
                .filter(e -> e.node.equals(node)).findFirst().orElse(null);
    }

    public static PaperTitleEnum getByTitle(String title) {
        if (StringUtils.isBlank(title)) {
            return null;
        }
        return Arrays.stream(PaperTitleEnum.values())
                .filter(e -> e.title.equals(title)).findFirst().orElse(null);
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
